import 'package:flutter/material.dart';

import '../constants.dart';

class PullDownToRefreshAnimation extends StatefulWidget {
  @override
  _PullDownToRefreshAnimationState createState() => _PullDownToRefreshAnimationState();
}

class _PullDownToRefreshAnimationState extends State<PullDownToRefreshAnimation> with SingleTickerProviderStateMixin{
  AnimationController _animation;

  @override
  void initState() {
    _animation = AnimationController(vsync: this, duration: Duration(seconds: 2))
      ..repeat();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(bottom: 4),
      width: double.infinity,
      height: topLoadingIconHeight,
      child: AnimatedBuilder(
        animation: _animation,
        builder: (_, __) {
          var index = ((_animation.value / 1.0) * 36)
              .round()
              .toInt();
          return topLoadingAnimationAssets[index];
        },
      ),
    );
  }

  @override
  void dispose() {
    _animation.dispose();
    super.dispose();
  }
}
List<Image> topLoadingAnimationAssets = List.generate(37, (index) {
  if (index >= 24 && index <= 30) {
    index = 23;
  } else if (index >= 33 && index <= 36) {
    index = 32;
  }
  var img = index.toString().padLeft(2, '0');
  return Image.asset(
      "assets/loading_anim/wm_common_img_loading_list_$img.webp");
});